/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import junit.framework.TestCase;

import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class ViaHeaderParserTest extends TestCase {
    public ViaHeaderParserTest(String name) {
        super(name);
    }

    public void test() {
        final byte[] data = "Via: SIP/2.0/TCP client.atlanta.example.com:5060;branch=z9hG4bK74b76;received=192.0.2.101, SIP/2.0/UDP sip.jnetx.ru:5061".getBytes();
        final ViaHeaderParser parser = new ViaHeaderParser();
        ViaHeaderImpl[] headers;
        try {
            headers = parser.parse(data, 4, data.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 2, headers.length);

        assertEquals("The protocol is wrong!", "SIP/2.0", headers[0].getProtocol());
        assertEquals("The transport is wrong!", "TCP", headers[0].getTransport());
        assertEquals("The host is wrong!", "client.atlanta.example.com", headers[0].getHost());
        assertEquals("The port is wrong!", 5060, headers[0].getPort());
        assertEquals("The branch is wrong!", "z9hG4bK74b76", headers[0].getBranch());
        assertEquals("The received is wrong!", "192.0.2.101", headers[0].getReceived());
        assertEquals("The string representation is wrong!", "Via: SIP/2.0/TCP client.atlanta.example.com:5060;branch=z9hG4bK74b76;received=192.0.2.101", headers[0].toString());

        assertEquals("The protocol is wrong!", "SIP/2.0", headers[1].getProtocol());
        assertEquals("The transport is wrong!", "UDP", headers[1].getTransport());
        assertEquals("The host is wrong!", "sip.jnetx.ru", headers[1].getHost());
        assertEquals("The port is wrong!", 5061, headers[1].getPort());
        assertNull("The branch is not null!", headers[1].getBranch());
        assertNull("The received is not null!", headers[1].getReceived());
        assertEquals("The string representation is wrong!", "Via: SIP/2.0/UDP sip.jnetx.ru:5061", headers[1].toString());
    }
}
/*
 * $Log$
 */